package org.test.client.ui.component.panel;

import java.awt.Container;
import java.awt.Cursor;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import org.test.client.ui.util.UIConstants;

public class MouseListenerForPanelIcon extends MouseAdapter{
	private TitlePanePanel panel;
	private  Container parent = null;
	private Rectangle rectClose = null;
	private Rectangle rectColl = null;
	private Rectangle rectConfig = null;
	
	public MouseListenerForPanelIcon(TitlePanePanel tp ){
		this.panel = tp;
		 Container parent = panel.getParent();
		 rectClose = panel.getRectClose();
		 rectColl = panel.getRectColl();
		 rectConfig = panel.getRectConfig();
	}
	
	@Override
	public void mouseMoved(MouseEvent me) {
		Point nowp = me.getPoint();
		if(rectClose!=null && rectClose.contains(nowp)){
			panel.setCursor(UIConstants.handCursor);
			return ;
		}
		if(rectConfig!=null && rectColl.contains(nowp)){
			panel.setCursor(UIConstants.handCursor);
			return ;
		}
		if(rectConfig!=null &&rectConfig.contains(nowp)){
			panel.setCursor(UIConstants.handCursor);
			return ;
		}
		if(panel.getCursor().getType() != Cursor.DEFAULT_CURSOR){
			panel.setCursor(UIConstants.defaultCursor);
		}
	}
	
	@Override
	public void mouseClicked(MouseEvent me) {
		Point nowp = me.getPoint();
		if(rectClose.contains(nowp)){
			panel.doClose(me);
			return ;
		}
		if(rectColl.contains(nowp)){
			panel.doExpand(me);
			return ;
		}
		if(rectConfig!=null &&rectConfig.contains(nowp)){
			panel.doConfig(me);
			return ;
		}
	}

	public TitlePanePanel getPanel() {
		return panel;
	}

	public void setPanel(TitlePanePanel panel) {
		this.panel = panel;
		parent = panel.getParent();
	}

	public Rectangle getRectClose() {
		return rectClose;
	}

	public void setRectClose(Rectangle rectClose) {
		this.rectClose = rectClose;
	}

	public Rectangle getRectColl() {
		return rectColl;
	}

	public void setRectColl(Rectangle rectColl) {
		this.rectColl = rectColl;
	}

	public Rectangle getRectConfig() {
		return rectConfig;
	}

	public void setRectConfig(Rectangle rectConfig) {
		this.rectConfig = rectConfig;
	}
	
}
